package xyz.xiangyushui.controller.manager.analysis;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import xyz.xiangyushui.dao.SalesHistoryDao;

/**
 * Servlet implementation class SalesTotalPost
 */
@WebServlet("/manager/salesDaily")
public class SalesTotalPost extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private SalesHistoryDao shd;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SalesTotalPost() {
        super();
        shd=new SalesHistoryDao();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String store=request.getParameter("store");
		String month=request.getParameter("month");
		if(store.equals("")||month.equals("")){
			response.sendRedirect(request.getContextPath()+"/manager/dataAnalysis");
		}else{
			int storeId=Integer.parseInt(store.split("-")[0]);
			int monthI=Integer.parseInt(month.split(" ")[0]);
			request.setAttribute("dailyTotal",shd.getDailyTotal(storeId, monthI));
			request.getRequestDispatcher("/manager/dataAnalysis").forward(request, response);
		}
		
	}

}
